package com.corona.game;

import com.corona.Game;

/* compiled from: Battle.java */
/* loaded from: pokewilds.jar:com/pkmngen/game/RestoreHealth.class */
public class RestoreHealth extends Action {
    Pokemon pokemon;
    int damage;
    int finalHealth;
    int timer = 3;
    int removeNumber = 1;
    int sign = 1;

    public RestoreHealth(Pokemon pokemon, int damage, Action nextAction) {
        super(new Object[0]);
        this.damage = 0;
        this.pokemon = pokemon;
        this.damage = damage;
        this.nextAction = nextAction;
    }

    @Override // com.corona.game.Action
    public String getCamera() {
        return "gui";
    }

    @Override // com.corona.game.Action
    public void firstStep(Game game) {
        this.finalHealth = this.pokemon.currentStats.get("hp").intValue() - this.damage;
        if (this.finalHealth > this.pokemon.maxStats.get("hp").intValue()) {
            this.finalHealth = this.pokemon.maxStats.get("hp").intValue();
        } else if (this.finalHealth < 0) {
            this.finalHealth = 0;
        }
        if (this.finalHealth > this.pokemon.currentStats.get("hp").intValue()) {
            this.sign = -1;
        }
        this.removeNumber *= this.sign;
    }

    @Override // com.corona.game.Action
    public void step(Game game) {
        this.timer++;
        if (this.timer >= 2) {
            this.timer = 0;
            int removeHealth = (int) Math.ceil((double) ((((float) this.removeNumber) / 48.0f) * ((float) this.pokemon.maxStats.get("hp").intValue())));
            if (removeHealth <= 0) {
                removeHealth = 1 * this.sign;
            }
            this.pokemon.currentStats.put("hp", Integer.valueOf(this.pokemon.currentStats.get("hp").intValue() - removeHealth));
            if (game.battle.drawAction != null) {
                if (this.pokemon == game.battle.oppPokemon) {
                    game.battle.drawAction.drawEnemyHealthAction.currHealth = (int) Math.ceil((double) ((((float) this.pokemon.currentStats.get("hp").intValue()) * 48.0f) / ((float) this.pokemon.maxStats.get("hp").intValue())));
                    game.battle.drawAction.drawEnemyHealthAction.updateHealthBarColor();
                } else if (this.pokemon == game.player.currPokemon) {
                    game.battle.drawAction.drawFriendlyHealthAction.currHealth = (int) Math.ceil((double) ((((float) this.pokemon.currentStats.get("hp").intValue()) * 48.0f) / ((float) this.pokemon.maxStats.get("hp").intValue())));
                    game.battle.drawAction.drawFriendlyHealthAction.currHealthRemaining = this.pokemon.currentStats.get("hp").intValue();
                    game.battle.drawAction.drawFriendlyHealthAction.updateHealthBarColor();
                }
            }
            this.removeNumber = 1;
            this.removeNumber *= this.sign;
            if ((this.sign == 1 && this.pokemon.currentStats.get("hp").intValue() <= this.finalHealth) || (this.sign == -1 && this.pokemon.currentStats.get("hp").intValue() >= this.finalHealth)) {
                this.pokemon.currentStats.put("hp", Integer.valueOf(this.finalHealth));
                if (!(game.battle.drawAction == null || game.battle.drawAction.drawFriendlyHealthAction == null || this.pokemon != game.player.currPokemon)) {
                    game.battle.drawAction.drawFriendlyHealthAction.currHealthRemaining = this.pokemon.currentStats.get("hp").intValue();
                }
                game.actionStack.remove(this);
                game.insertAction(this.nextAction);
            }
        }
    }
}
